package com.android.monee.data.model;

import java.util.Date;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import com.android.monee.data.access.IdNClone;

public class Mensuality implements IdNClone<Integer, Mensuality>, Comparable<Mensuality>{

	private Integer id;
//	private Budget budget;
	private Integer budgetId;
	private int number;
	private float amount;
	private Date date;
	private boolean done;
	private boolean cancelled;

	public Mensuality(Mensuality mensuality) {
		this.id = mensuality.getId();
		this.budgetId = mensuality.getBudgetId();
		//		this.budget = mensuality.getBudget();
		this.number = mensuality.getNumber();
		this.amount = mensuality.getAmount();
		this.date = mensuality.getDate();
		this.done = mensuality.isDone();
		this.cancelled = mensuality.isCancelled();
	}

	public Mensuality(/*Budget budget*/) {
		//this.budget = budget;
		this.done = false;
	}
	
	public Mensuality(Budget budget) {
		this.budgetId = budget.getId();
		this.done = false;
	}
	

	@Override
	public Mensuality clone() {
		Mensuality clone = null;
		try {
			clone = (Mensuality) super.clone();
			if(this.date != null)
				clone.date = (Date) this.date.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return clone;
	}

	@Override
	public boolean equals(Object o){
		return EqualsBuilder.reflectionEquals(this, o);
	}
	
	@Override
	public int hashCode(){
		return HashCodeBuilder.reflectionHashCode(this);
	}
	
	@Override
	public int compareTo(Mensuality another) {
		return this.date.compareTo(another.getDate());
	}
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	//TODO, une fois que la classe Mensuality sera l'objet metier, supprimer cette propriété, les id c'est pour implémenter le modèle relationnel.
	public Integer getBudgetId() {
		return budgetId;
	}

	public void setBudgetId(Integer budgetId) {
		this.budgetId = budgetId;
	}

	public float getAmount() {
		return amount;
	}

	public void setAmount(float amount) {
		if(isDone() && this.amount > 0)
			throw new RuntimeException("Impossible de modifier le montant d'une mensualité DONE. "+this.amount);
		this.amount = amount;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public boolean isDone() {
		return done;
	}

	public void setDone(boolean done) {
		this.done = done;
	}

	public boolean isCancelled() {
		return cancelled;
	}

	public void setCancelled(boolean cancelled) {
		this.cancelled = cancelled;
	}

//	public Budget getBudget() {
//		return budget;
//	}
//
//	public void setBudget(Budget budget) {
//		this.budget = budget;
//	}
	
	
}
